Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

629
Visualizações
Rails 2.4 => 3.0: ActiveRecord: `add_modifier`: wrong number of arguments (given 3, expected 2) (ArgumentError)

When I update my Ruby version from 2.4.3 to 3.0.2, (bundle update), and try to run the Rails console, I get this error message. How can I resolve this?

C:\Users\Chloe\workspace\catalyst_research>rails console
C:/ruby30/lib/ruby/gems/3.0.0/gems/activerecord-5.0.7.2/lib/active_record/type/adapter_specific_registry.rb:7:in `add_modifier': wrong number of arguments (given 3, expected 2) (ArgumentError)
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/activerecord-5.0.7.2/lib/active_record/type.rb:22:in `add_modifier'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:827:in `<class:PostgreSQLAdapter>'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:69:in `<module:ConnectionAdapters>'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `<module:ActiveRecord>'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/activerecord-5.0.7.2/lib/active_record/connection_adapters/postgresql_adapter.rb:19:in `<main>'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from C:/ruby30/lib/ruby/gems/3.0.0/gems/activesupport-5.0.7.2/lib/active_support/dependencies.rb:293:in `block in require'
...
C:/Users/Chloe/workspace/catalyst_research/config/environment.rb:5:in
...

Gemfile:

ruby '~>2.4.1'#'~>3.0.2'
gem 'rails', '~> 5.0.2'
...

environment.rb:5:

Rails.application.initialize!

adapter_specific_registry.rb:7:

  6     class AdapterSpecificRegistry < ActiveModel::Type::Registry
  7       def add_modifier(options, klass, **args)
  8         registrations << DecorationRegistration.new(options, klass, **args)
  9       end
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Rails 5.0.X is not compatible with Ruby 3.0 - period. And that won't change as its no longer maintained.

Rails 6.0.2 is the earliest Rails version which is compatible with Ruby 3.0.

Ruby 3.0 has some significant changes. Especially the separation of keyword arguments from positional arguments which is the most likely cause of the error you're getting.

In previous versions of Ruby you could call the method as:

add_modifier({ foo: 1 }, klass, { bar : 1 })

And Ruby would automatically convert the last positional argument to keyword arguments. This was deprecated and will issue a warning in Ruby 2.7 and was completely removed in Ruby 3.0. You're getting (given 3, expected 2) as the last argument is treated as a positional argument.

If you want to pass a hash as keyword arguments in Ruby 3 you need to use a double splat to convert it:

add_modifier({ foo: 1 }, klass, **{ bar : 1 })

TLDR

You need to find a different upgrade path where you upgrade your Ruby version incrementally as you upgrade the project to newer versions of Rails.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda